//------
//HEADER FILE
//---------------
#ifndef PLAYER_H
#define PLAYER_H

//Header files
#include <nds.h>
#include <math.h>
#include <vector>
#include "fixed.h"
#include "ellen/ln.h"
#include "reference.h"
#include "weapon.h"
#include "game.h"
#include "scorekeeper.h"

//sprite
#include "megaman3.h"
#include "lifebar.h"
#include "ammoCounter.h"

//sounds
#include "jump_1_22050_8_s_raw.h"
#include "footsteps_1_22050_8_s_raw.h"
#include "blaster_1_22050_8_s_raw.h"

using namespace std;
//class Game;

class Player {

	public:
	  static Player *getInstance();
	  virtual ~Player();
	  lnSprite* getSprite();

	  void update();
	  void handleAnimation();
	  void display();
	  void updateInput(touchPosition * touch);
	  void handleInput(TransferSoundData * soundData,TransferSoundData * soundData2,TransferSoundData * soundData3, touchPosition * touch);
	  void setHidden(bool hidden);
	  void reset();

	  //player actions
      void move(int direction);
      void jump();
	  void attack();
	  void attack2();

	  void generateBullet();
	  void generateBullet2();
	  void playerDidHit(int index);
	  void setWeapon(weapon newWeapon);
	  void setWeapon2(weapon newWeapon);
	  void addAmmo();

	  void healthPack();
	  void tookDamage(int damage);
	  bool isDead();

	  void setPos(tFloat posX,tFloat posY);
	  void setOffset(tFloat offsetX,tFloat offsetY);
	  void setBounds();
	  void setPrevBounds();

	  void applyGravity();
      void applyFriction();

	  //Collision checks.
	  bool checkCollide(BoundingBox target);
	  bool checkCollideXprev(BoundingBox target);
	  bool checkCollideYprev(BoundingBox target);
      bool checkWeaponCollide(BoundingBox target);

	  //Responses to collison.
	  void requestFullStop();
	  void requestHover();
	  void requestFall();
	  void hitGround();
	  void reverse();
	  void speedUp();
	  void lessFriction(bool isThere);
	  void knockback(int direction);

	  t2DVector getPosition();
	  t2DVector getPositionPrev();
	  t2DVector getOffset();
	  t2DVector getVelocity();
	  BoundingBox getBounds();
	  BoundingBox getPrevBounds();

	  //AKS
	  //TODO:  Better method for sounds
	  TransferSoundData initSounds();
	  TransferSoundData initSounds2();
	  TransferSoundData initSounds3();
	  void printInfo(t2DVector camera);

   private:
	   Player();
	   static Player * m_instance;

	//   game* Game;
	   //Properties of character
	   bool m_facingRight;
	   bool m_inAir;
	   bool m_attacking;
	   bool m_icy;
	   bool m_invincible;
	   int m_attackDirection;

	   tFloat m_maxSpeedX;
	   tFloat m_maxSpeedY;
	   tFloat m_runSpeed;
	   tFloat m_jumpSpeed;
	   tFloat m_friction;
	   tFloat m_gravityConstant;
	   tFloat m_prevMaxSpeedX;
	   tFloat m_prevMaxSpeedY;
	   tFloat m_prevRunSpeed;
	   tFloat m_prevJumpSpeed;
	   tFloat m_prevFriction;

	   int m_jumpCount;
	   int invincibleCounter;

	   touchPosition touch;

	  //character sounds
		TransferSoundData jump_sound;
		TransferSoundData attack_sound;
		TransferSoundData walk_sound;

		BoundingBox m_boundingBox;
		BoundingBox m_prevBoundingBox;

		t2DVector position;
		t2DVector prevPosition;
		t2DVector localPos;
		t2DVector velocity;
		t2DVector playerOffset;

		int frames;
		int counter;
		int m_speedUpTimer;

		weapon m_curWeapon;
		weapon m_secondWeapon;
		int m_secondaryAmmo;

		int m_health;

		lnSprite* m_sprite;
		lnSpriteAnim* m_spriteAnim;

		lnSprite* m_healthBarSprite;
		lnSpriteAnim* m_healthBarSpriteAnim;

		lnSprite* m_ammoCounter;
		lnSpriteAnim* m_ammoCounterAnim;
};

#endif 